package cn.zhouyafeng.shares;

import org.apache.commons.lang3.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;

public class ShareTestMain {

    static HashMap<ShareObj, Double> map = new HashMap<ShareObj, Double>();

    static {
        map.put(new ShareObj("600016", " --ms"), 0d);
//        map.put(new ShareObj("601328", " --交通", 5.732), 0d);
    }

    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

        Timer dTimer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                map.forEach((obj, val) -> {
                    ShareResult price = obj.getPrice();
                    if (StringUtils.isNotBlank(price.msg)) {
                    }
                    if (price.price != val) {
                        val = price.price;
                        System.out.println(val + obj.getName() + " -- " + sdf.format(new Date()));
                    }
                    map.put(obj, price.price);

                });
            }
        };

        dTimer.schedule(timerTask, new Date(), 10 * 1000L);//24* 60* 60 * 1000
    }
}
